/**
 *
 * @author Erivaldo Lourenco
 * @author Juliana Cavalcanti
 * 
 */

package br.ufal.ic.p3.Interface;

//import br.ufal.ic.p3.Interface.Sobre;
import br.ufal.ic.p3.Interface.cliente.juridico.CadastroClienteJuridico;
import br.ufal.ic.p3.Interface.funcionario.CadastroFuncionario;
import br.ufal.ic.p3.controle.ControleCliente;
import br.ufal.ic.p3.controle.ControleClienteJuridico;
import br.ufal.ic.p3.controle.ControleFuncionario;
import br.ufal.ic.p3.funcionario.Funcionario;

import javax.swing.GroupLayout.Alignment;
import javax.swing.JInternalFrame;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.GroupLayout;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.JTable;
import javax.swing.ImageIcon;

import java.awt.Color;
import java.awt.SystemColor;

public class Consulta extends JInternalFrame {
	private JTable tabela;
	private String x = "Teste";
	private boolean testeF = false;
	private boolean testeC = false;
	private boolean testeJ = false;
	
	public Consulta() {
		super("ProgNet - Consulta");
		getContentPane().setBackground(Color.WHITE);
		initComponents();
	}

	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {
		labelMensagemTopo = new javax.swing.JLabel();
		barraMenu = new javax.swing.JMenuBar();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		labelMensagemTopo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
		labelMensagemTopo
				.setText("Por favor, digite o numero de CPF/CNPJ do Cliente ou Funcionario:");

		setJMenuBar(barraMenu);

		campoPesquisa = new JTextField();
		campoPesquisa.setColumns(10);

		JRadioButton rdbtnCliente = new JRadioButton("Cliente");

		JRadioButton rdbtnClienteJuridico = new JRadioButton("Cliente Juridico");

		JRadioButton rdbtnFuncionario = new JRadioButton("Funcionario");
		rdbtnFuncionario.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				testeF = true;
			}
		});

		botaoCancelar = new JButton("Cancelar");
		botaoCancelar.setIcon(new ImageIcon(Consulta.class.getResource("/br/ufal/ic/p3/imagens/cancelar.png")));
		botaoCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		
		
		Object [][] dados = { {"Nome", "Sobrenome", "CPF"}, {null, null, null}};
		String [] colunas = {"Nome", "Sobrenome", "CPF"};
		//ArrayList<String> array = new ArrayList<String>();
		
		tabela = new JTable(dados, colunas);
		tabela.setBackground(SystemColor.inactiveCaptionBorder);
		
		JButton botaoDeletar = new JButton("Deletar");
		botaoDeletar.setIcon(new ImageIcon(Consulta.class.getResource("/br/ufal/ic/p3/imagens/deletar.png")));

		JButton botaoAtualizar = new JButton("Atualizar");
		botaoAtualizar.setIcon(new ImageIcon(Consulta.class.getResource("/br/ufal/ic/p3/imagens/atualizar.png")));

		botaoPesquisa = new JButton("Pesquisar");
		botaoPesquisa.setIcon(new ImageIcon(Consulta.class.getResource("/br/ufal/ic/p3/imagens/consultar.png")));
		botaoPesquisa.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if (testeF == true) {
					ControleFuncionario funcionario = new ControleFuncionario();
					ArrayList<String> a = funcionario
							.buscarFuncionarioCPF(campoPesquisa.getText());
					
					System.out.println(a);
				}
				
				else if (testeC == true) {
					ControleCliente cliente = new ControleCliente();
					ArrayList<String> a = cliente
							.buscarClienteCPF(campoPesquisa.getText());
					
					System.out.println(a);
				}
				
				else if (testeJ == true) {
					ControleClienteJuridico clienteJuridico = new ControleClienteJuridico();
					ArrayList<String> a = clienteJuridico
							.buscarClienteJuridicoCNPJ(campoPesquisa.getText());
					
					
					
					System.out.println(a);

				}
				
				else {
					System.out.println("Por favor, selecione uma das opcoes acima.");
				}
				
				
				//System.out.println(a);
				
				//tabela.addText(funcionario.buscarFuncionarioNome(x));
		        //tabela.setText(funcionario.buscarFuncionarioNome(x));
		        
			}
		});
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(12)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(labelMensagemTopo)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(campoPesquisa, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(botaoPesquisa))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(rdbtnCliente)
									.addGap(10)
									.addComponent(rdbtnClienteJuridico)
									.addGap(4)
									.addComponent(rdbtnFuncionario))))
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addComponent(tabela, GroupLayout.PREFERRED_SIZE, 764, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
								.addComponent(botaoDeletar, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(botaoCancelar, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
							.addGap(34)
							.addComponent(botaoAtualizar)))
					.addContainerGap(63, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(22)
					.addComponent(labelMensagemTopo)
					.addGap(8)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(rdbtnCliente)
						.addComponent(rdbtnClienteJuridico)
						.addComponent(rdbtnFuncionario))
					.addGap(12)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(campoPesquisa, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
						.addComponent(botaoPesquisa))
					.addGap(18)
					.addComponent(tabela, GroupLayout.PREFERRED_SIZE, 196, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(botaoDeletar)
						.addComponent(botaoAtualizar))
					.addGap(28)
					.addComponent(botaoCancelar)
					.addGap(22))
		);
		getContentPane().setLayout(groupLayout);

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private javax.swing.JMenuBar barraMenu;
	private javax.swing.JLabel labelMensagemTopo;
	private JTextField campoPesquisa;
	private JButton botaoCancelar;

	private JButton botaoPesquisa;
}
